/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TipoTexto.java
 *
 * Created on 22-jun-2012, 0:11:47
 */
package sistemadeproyectos;

import java.awt.Image;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author giancarlo
 */
public class TipoTexto extends javax.swing.JDialog {

    public boolean aceptar;
    public FileInputStream documento;
    private DefaultListModel<String> opciones;
    
    /** Creates new form TipoTexto */
    public TipoTexto(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        opciones = new DefaultListModel<String>();
        opciones.addElement("Documento en Blanco");
        opciones.addElement("Plantilla de Carta");
        opciones.addElement("Plantilla de Examen");
        opciones.addElement("Plantilla de Fax");
        opciones.addElement("Plantilla de Curriculum");
        ListPlantillas.setModel(opciones);
        
        String ruta = "";
        if(System.getProperty("os.name").substring(0,5).equals("Windo")){
            ruta = "\\src\\sistemadeproyectos\\images\\iconosEditor\\";
        }
        else if(System.getProperty("os.name").substring(0,5).equals("Linux")){
            ruta = "/src/sistemadeproyectos/images/iconosEditor/";
        }
        Aceptar_button.setIcon(ajustarImagen(System.getProperty("user.dir") 
                + ruta + "Aceptar.png", (Aceptar_button.getWidth()/2), (Aceptar_button.getHeight()/2)));
        Cancelar_button.setIcon(ajustarImagen(System.getProperty("user.dir") 
                + ruta + "Cancelar.png", (Cancelar_button.getWidth()/2), (Cancelar_button.getHeight()/2)));
    }

    private ImageIcon ajustarImagen(String ico, int ancho, int alto) {
        ImageIcon tmpIconAux = new ImageIcon(ico);
        //Escalar Imagen
        ImageIcon tmpIcon = new ImageIcon(tmpIconAux.getImage().getScaledInstance(ancho, alto, Image.SCALE_DEFAULT));
        return tmpIcon;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ListPlantillas = new javax.swing.JList();
        Aceptar_button = new javax.swing.JButton();
        Cancelar_button = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemadeproyectos.SistemadeproyectosApp.class).getContext().getResourceMap(TipoTexto.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED), resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jPanel1.border.titleFont"), resourceMap.getColor("jPanel1.border.titleColor"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        ListPlantillas.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        ListPlantillas.setName("ListPlantillas"); // NOI18N
        jScrollPane1.setViewportView(ListPlantillas);

        Aceptar_button.setToolTipText(resourceMap.getString("Aceptar_button.toolTipText")); // NOI18N
        Aceptar_button.setName("Aceptar_button"); // NOI18N
        Aceptar_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Aceptar_buttonActionPerformed(evt);
            }
        });

        Cancelar_button.setToolTipText(resourceMap.getString("Cancelar_button.toolTipText")); // NOI18N
        Cancelar_button.setName("Cancelar_button"); // NOI18N
        Cancelar_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cancelar_buttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(252, 252, 252)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(Aceptar_button, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                    .addComponent(Cancelar_button, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(117, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(Aceptar_button, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addComponent(Cancelar_button, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(5, 5, 5)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Aceptar_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Aceptar_buttonActionPerformed
        int indice = ListPlantillas.getSelectedIndex();
        if ((indice >= 0) && (indice < (this.opciones).getSize())) {
            String opcion = opciones.getElementAt(indice);
            String ruta = "";
            if(System.getProperty("os.name").substring(0,5).equals("Windo")){
                ruta = "\\src\\sistemadeproyectos\\Plantillas\\";
            }
            else if(System.getProperty("os.name").substring(0,5).equals("Linux")){
                ruta = System.getProperty("user.dir") + "/src/sistemadeproyectos/Plantillas/";
            }
            File plantilla = new File(ruta+"blanco.prod");
                        
            if (opcion.equals("Plantilla de Carta"))
            { plantilla = new File(ruta+"carta.prod"); }
            else if (opcion.equals("Plantilla de Examen"))
            { plantilla = new File(ruta+"prueba.prod"); }
            else if (opcion.equals("Plantilla de Fax"))
            { plantilla = new File(ruta+"fax.prod"); }
            else if (opcion.equals("Plantilla de Curriculum"))
            { plantilla = new File(ruta+"curriculum.prod"); }
            
            try {
                this.documento = new FileInputStream(plantilla);
                this.aceptar = true;
                this.dispose();
            } 
            catch (FileNotFoundException e) {
                JOptionPane.showMessageDialog(this, "Error al crear el documento: "+ e.getMessage(), 
                   "Error al Abrir", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_Aceptar_buttonActionPerformed

    private void Cancelar_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cancelar_buttonActionPerformed
        this.dispose();
    }//GEN-LAST:event_Cancelar_buttonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TipoTexto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TipoTexto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TipoTexto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TipoTexto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                TipoTexto dialog = new TipoTexto(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Aceptar_button;
    private javax.swing.JButton Cancelar_button;
    private javax.swing.JList ListPlantillas;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
